package com.hx.petsever.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hx.petsever.entity.Address;
import com.hx.petsever.mapper.AddressMapper;
import com.hx.petsever.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {

    @Autowired
    AddressMapper addressMapper;

    @Override
    public HashMap DeleteOne(String name, String phone, String address, String userid) {
        addressMapper.DeleteOne(name,phone,address,userid);
        HashMap<String , String> map = new HashMap<>();
        map.put("msg","删除成功");
        return map;
    }

    @Override
    public HashMap getAllbyId(String userid) {
        List<Address> addressList = addressMapper.getAllbyId(userid);
        HashMap<String , Object> map = new HashMap<>();
        if(addressList.isEmpty())
        {
            map.put("msg","数据为空");
            map.put("state","0");
        }else {
            map.put("state",1);
            map.put("msg",addressList);
        }
        return map;
    }


    @Override
    public HashMap InsertAddress(String name, String phone, String address, String userid ,String defaults) {
        Address ad = addressMapper.getOn(name, phone, address, userid);
        HashMap<String, String> map = new HashMap<>();
        if( ad != null)
        {
            map.put("msg","该地址已存在");
            map.put("state","0");
        }
        else {
            addressMapper.InsertAddress(name,phone,address,userid,defaults);
            map.put("msg","插入成功");
            map.put("state","1");
        }
        return map;
    }
}
